<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改词缀</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">

			<div class="form-group">
				<label class="col-xs-2 text-right">游戏:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="gameId" name="gameId" value="${page.wm.ROW_ID}" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[USE_FLAG]=1&wm[DEL_FLAG]=1" onchange="TagUtil.fillOptions('gameId');">
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="gameName" id="gameName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">装备分类:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="parentId" name="equipParentId" value="${page.wm.ROW_ID}" requiredInit="true" parentParamName="gameId" parentCascadedSelect="gameId" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?wm[TYPE_FLAG]=11&wm[OPEN_FLAG]=1" onchange="TagUtil.fillOptions('parentId');">
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="equipParentName" id="equipParentName" value="">
				</div>
			</div>

			<div class="form-group">
				<label class="col-xs-2 text-right">装备类型:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="equipTypeId" name="equipTypeId" value="${page.wm.EQUIP_TYPE_ID}" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1" parentCascadedSelect="parentId" parentParamName="parentId" onchange="TagUtil.fillOptions('equipTypeId');" >
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="equipType" id="equipType" value="">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">词缀类型:</label>
				<div class="col-xs-4">
					<select class="form-control select" id="affixType" name="affixType">
						<option value="">请选择</option>
						<option value="0">前缀</option>
						<option value="1">后缀</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">词缀属性：</label>
				<div class="col-xs-10">
					<textarea name="affixProperty" id="affixProperty"  style="width:400px;height:100px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>

			<div class="form-group">
				<label class="col-xs-2 text-right">Tier:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="affixTier" id="affixTier" value=""  placeholder="请输入Tier">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">词缀:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="affixContent" id="affixContent" value=""  placeholder="请输入词缀内容">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">等级:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="affixLevel" id="affixLevel" value=""  placeholder="请输入等级">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">词缀属性范围：</label>
				<div class="col-xs-10">
					<textarea name="affixPropertyScope" id="affixPropertyScope"  style="width:400px;height:100px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">几率:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="prob" id="prob" value=""  placeholder="请输入几率">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">价格:</label>
				<div class="col-xs-10">
					<textarea name="price" id="price"  style="width:400px;height:100px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/></textarea>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-2 text-right">是否开启:</label>
				<div class="col-xs-7">
					<td colspan="2">
						<label for="port"><input id="yse" name="openFlag" checked="checked" type="radio" value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label for="no"><input id="no" name="openFlag" type="radio" value="0"/>&nbsp;否</label>
					</td>
				</div>
			</div>

			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="gameIcon" name="gameImgPage" value="${tlzsGame.gameIcon}">
           	<input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">
$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    var rowId = $("#rowId").val();
    if(rowId > 0){
        $.ajax({
            url: "${userInfoV1}/gameEquipAffix/getGameEquipAffixInfo?r="+Math.random(),
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#gameId").val(data.gameId);
                $("#gameName").val(data.gameName);
                $("#parentId").val(data.equipParentId);
                $("#equipParentName").val(data.equipParentName);
                $("#equipTypeId").val(data.equipTypeId);
                $("#equipType").html(data.equipType);
                $("#affixType").val(data.affixType);
                if(data.affixType == 0){
                    $("#affixType").find("option[text='前缀']").attr("selected",true);
                }else if(data.affixType == 1){
                    $("#affixType").find("option[text='后缀']").attr("selected",true);
                }
                $("#affixProperty").val(data.affixProperty);
                $("#affixTier").val(data.affixTier);
                $("#affixContent").val(data.affixContent);
                $("#affixLevel").val(data.affixLevel);
                $("#affixPropertyScope").val(data.affixPropertyScope);
                $("#prob").val(data.prob);
                $("#price").val(data.price);


                if(data.openFlag == 1){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
                
                fillBigType();
                fillAreaServer(data.equipParentId,data.equipTypeId);
            }
        });
    }
})

function fillBigType(){
    var token = $("#token").val();
    $.ajax({
        url: "${userInfoV1}/gameGoodsType/typeSelect?wm[TYPE_FLAG]=11",
        type: "post",
        cache: false,
        data:{"token":token},
        dataType:"json",
        async:false,
        success: function(data) {
            if (data == null) {
                return;
            }
            $("#parentId").empty();
            $.each(data, function (index, item) {
                var id = item.value;
                var text = item.label;
                // $("#areaId").append("<option value='"+id+"'>"+text+"</option>");
                var option = "<option value='"+id+"' "
                if (equipTypeId == id){
                    option += " selected = 'selected'  ";
                }
                option += " >"+text+"</option>"
                $("#parentId").append(option);
            });
        }
    });
}


function fillAreaServer(parentId,equipTypeId){
    var token = $("#token").val();
    if(parentId > 0){
        $.ajax({
            url: "${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1",
            type: "post",
            cache: false,
            data:{"parentId":parentId, "token":token},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#equipTypeId").empty();
                $.each(data, function (index, item) {
                    var id = item.value;
                    var text = item.label;
                    // $("#areaId").append("<option value='"+id+"'>"+text+"</option>");
                    var option = "<option value='"+id+"' "
                    if (equipTypeId == id){
                        option += " selected = 'selected'  ";
                    }
                    option += " >"+text+"</option>"
                    $("#equipTypeId").append(option);
                });
            }
        });
    }
}




var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }

    var gameId = $.trim($("#gameId").val());
    if (!CheckUtil.isNotNull(gameId)) {
        layer.msg("请选择游戏!");
        return;
    }

    var gameName = $("#gameId").find("option:selected").text();
    $("#gameName").val(gameName);

    var parentId = $.trim($("#parentId").val());
    if (!CheckUtil.isNotNull(parentId)) {
        layer.msg("请选择装备类型!");
        return;
    }

    var equipParentName = $("#parentId").find("option:selected").text();
    $("#equipParentName").val(equipParentName);


    var equipTypeId = $.trim($("#equipTypeId").val());
    if (!CheckUtil.isNotNull(equipTypeId)) {
        layer.msg("请选择装备分类!");
        return;
    }

    var equipType = $("#equipTypeId").find("option:selected").text();
    $("#equipType").val(equipType);


    var affixType = $('#affixType').val();
    if (!CheckUtil.isNotNull(affixType)) {
        layer.msg("词缀类型不能为空!");
        return;
    }

    var affixProperty = $('#affixProperty').val();
    if (!CheckUtil.isNotNull(affixProperty)) {
        layer.msg("词缀属性不能为空!");
        return;
    }

    var affixTier = $('#affixTier').val();
    if (!CheckUtil.isNotNull(affixType)) {
        layer.msg("词缀affixTier不能为空!");
        return;
    }

    var affixContent = $('#affixContent').val();
    if (!CheckUtil.isNotNull(affixType)) {
        layer.msg("词缀内容不能为空!");
        return;
    }

    var affixLevel = $('#affixLevel').val();
    if (!CheckUtil.isNotNull(affixLevel)) {
        layer.msg("词缀等级不能为空!");
        return;
    }

    var affixPropertyScope = $('#affixPropertyScope').val();
    if (!CheckUtil.isNotNull(affixPropertyScope)) {
        layer.msg("属性范围不能为空!");
        return;
    }
    var prob = $('#prob').val();
    if (!CheckUtil.isNotNull(prob)) {
        layer.msg("属性范围不能为空!");
        return;
    }
    var price = $('#price').val();
    if (!CheckUtil.isNotNull(price)) {
        layer.msg("属性范围不能为空!");
        return;
    }

    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${userInfoV1}/gameEquipAffix" + action[i],
        type: "post",
        cache: false,
        //data:parseJson(decodeURIComponent($("#saveAndUpdateFrom").serialize())),
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
    
/*    
    $("#saveAndUpdateFrom").attr("action", "${userInfoV1}/baseGame" + action[i]);
    if ($("#isReCommit").val() == 0) {
        $("#isReCommit").val(1);
        //loading层
        var index = layer.load(0, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        //$("#saveAndUpdateFrom").submit();
    } */
}

function checkGameName() {
    //渠道游戏ID
    var gameName = $.trim($("#gameName").val());
    $("#gameName").val(gameName);//渠道游戏ID去空格
    var flag = $("#flag").val();
    var rowId = $("#rowId").val();;
    var aa = false;
    if (CheckUtil.isNotNull(gameName)) {
        $.ajax({
            type: "post",
            cache: false,
            url: "${userInfoV1}/baseGame/checkGameIsExist",
            data:{gameName:gameName, gameId:rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                aa = data;
            }
        });
    }
    return aa;
}
</script>
</html>